package com.project;

import com.lovo.netCRM.component.LovoImageLabel;
import com.lovo.netCRM.component.LovoTable;

import javax.swing.*;

public class MyJFrame extends JFrame implements Runnable{
       /*
        图片标签，第一个、第二个参数为坐标，第三个第四个参数为大小
        第五个参数为加入容器，第六个参数为图片路径
       */
    private LovoImageLabel imageLabel = new LovoImageLabel(30,30,150,150,this,
            "img/238c39bc3d2eaa4a51e8aa0f040907ec.jpg");



    public MyJFrame(){
        this.setLayout(null);

        this.setSize(800,600);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);

        //线程的启动
        new Thread(this).start();
    }

    public static void main(String[] args) {
        new MyJFrame();
    }

    @Override
    public void run() {
        int speed  = 5;
        int speed1 = 5;

        while (true) {
            //得到标签当前坐标
            int x = imageLabel.getX();
            int y = imageLabel.getY();
            if (x>=650||x<=0){
                speed*=-1;
            }
            if (y>=450||y<=0){
                speed1*=-1;
            }
            imageLabel.setLocation(x + speed,y+speed1);

            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
